**********************************************************************************************
//*SET USER*//
*Users Identification Code
*User 1
*User 2


//Set user below:
global user 2

//Enter the filepath of where the Master Folder is located//
*********************************************************
//User 1
if $user == 1 {
	global FH 
}
**********************************************************
//User 2
if $user == 2 {

	global FH ""
}
************************************************************
*************************PHILIPPINES************************
************************************************************
//GENERATING SCORES
do "$FH/do/Scores/PHL_HOC_Scores.do"

******************************************************************************************
******************************************************************************************
//*RE-CLASSIFICATION OF BASELINE PARAMETERS*//
///CLASSIFICATION OF RETAIL TYPE INTO 3 NEW TYPES: "SARI-SARI STORE", "FOOD RETAIL" AND "NON-FOOD RETAIL"///


tab b_retailtype
tab b_retailtype, nol
gen b_retailtype_new = 1 if b_retailtype == 1
replace b_retailtype_new = 3 if b_retailtype == 8
replace b_retailtype_new = 2 if b_retailtype_new != 1 & b_retailtype_new != 3
tab b_retailtype_new
label variable b_retailtype_new "Revised Retail Type Classification"
label define retailnew 1"Sari-Sari Store" 2"Food Retail" 3"Non-food Retail"
label values b_retailtype_new retailnew
tab b_retailtype_new
tab b_retailtype_new, nol
tab b_retailtype_new, gen(b_retailtype_new_)

*********************************************************************************
///RE-CLASSIFICATION OF EDUCATION INTO 4 LEVELS: "LESS THAN 5TH CLASS", "ABOVE 5TH CLASS", "COMPLETED HIGH SCHOOL" & "GRADUATE/POST-GRADUATE"///

tab b_education
tab b_education, nol
gen b_education_new = 1 if b_education <= 2
replace b_education_new = 2 if b_education == 3
replace b_education_new = 3 if b_education == 4
replace b_education_new = 4 if b_education >= 5
tab b_education_new
label variable b_education_new "revised education level"
label define educationnew 1"less than 5th class" 2"above 5th class" 3"complete high school" 4"graduate / post graduate"
label values b_education_new educationnew
tab b_education_new
tab b_education_new, nol
tab b_education_new, gen(b_education_new_)

bysort groupidentifier: gen stratum = _N

**********************************************************************************
///RENAMING INDICATOR ON WHETHER A PERSON OWNS A PHONE///
rename b_qg1 b_ownphone
replace b_ownphone =. if b_ownphone < 0
tab b_ownphone


//CORRECTING SPURIOUS VALUES//
replace b_bus_prime =. if b_bus_prime < 0

//RE-CLASSIFYING ORIENTATION 
tab orientation
tab orientation, nol

replace orientation = 5 if tcarm == 0
tab orientation
tab orientation, nol
tab orientation, gen(orientation_new_)
tab orientation_new_1
tab orientation_new_2
tab orientation_new_3
tab orientation_new_4
tab orientation_new_5


//by groupid, sort: gen nvals = _n == 1
//count if nvals
******************************************************************************************
//GENERATING LOG VALUES OF SALES IN BAD, GOOD & REGULAR WEEKS & REGULAR WEEK PROFITS//

/*
drop if e_qb3_total == 0
drop if b_qb3_total == 0

drop if e_qd3_total == 0
drop if b_qd3_total == 0
*/

pwcorr b_age b_urbanclas b_ageofbus b_bus_prime b_ownphone b_education_new b_retailtype_new


******************************************************************************************
//CONTROL MEANS OF OUTCOME VARIABLES//
summarize e_training_score if tcarm == 0
scalar mean1 = round(r(mean), 0.001)
scalar sd1 = round(r(sd), 0.001)

summarize e_training_score2 if tcarm == 0
scalar mean2 = round(r(mean), 0.001)
scalar sd2 = round(r(sd), 0.001)

summarize w1e_salesregwk if tcarm == 0
scalar mean3 = round(r(mean), 0.001)
scalar sd3 = round(r(sd), 0.001)

summarize log_e_salesregwk if tcarm == 0
scalar mean4 = round(r(mean), 0.001)
scalar sd4 = round(r(sd), 0.001)

summarize w1e_profitregwk if tcarm == 0
scalar mean5 = round(r(mean), 0.001)
scalar sd5 = round(r(sd), 0.001)

summarize log_e_profitregwk if tcarm == 0
scalar mean6 = round(r(mean), 0.001)
scalar sd6 = round(r(sd), 0.001)

//INTENT TO TREAT REGRESSIONS
reg e_training_score b_training_score tcarm stratum b_urbanclas b_ageofbus b_bus_prime b_ownphone b_education_new_2-b_education_new_4 b_retailtype_new_2-b_retailtype_new_3, cluster(groupid) 

matrix list r(table)

scalar b1 = round(_b[tcarm], 0.001)
scalar se1 = round(_se[tcarm], 0.01)
scalar p1 = round(r(table)[4,2], 0.001)
scalar N1 = e(N)

reg e_training_score2 b_training_score2 tcarm stratum b_urbanclas b_ageofbus b_bus_prime b_ownphone b_education_new_2-b_education_new_4 b_retailtype_new_2-b_retailtype_new_3, cluster(groupid) 

scalar b2 = round(_b[tcarm], 0.001)
scalar se2 = round(_se[tcarm], 0.01)
scalar p2 = round(r(table)[4,2], 0.001)
scalar N2 = e(N)

reg w1e_salesregwk w1b_salesregwk tcarm stratum b_urbanclas b_ageofbus b_bus_prime b_ownphone b_education_new_2-b_education_new_4 b_retailtype_new_2-b_retailtype_new_3, cluster(groupid)

scalar b3 = round(_b[tcarm], 0.001)
scalar se3 = round(_se[tcarm], 0.01)
scalar p3 = round(r(table)[4,2], 0.001)
scalar N3 = e(N)


reg log_e_salesregwk log_b_salesregwk tcarm stratum b_urbanclas b_ageofbus b_bus_prime b_ownphone b_education_new_2-b_education_new_4 b_retailtype_new_2-b_retailtype_new_3, cluster(groupid)

scalar b4 = round(_b[tcarm], 0.001)
scalar se4 = round(_se[tcarm], 0.01)
scalar p4 = round(r(table)[4,2], 0.001)
scalar N4 = e(N)

reg w1e_profitregwk w1b_profitregwk tcarm stratum b_urbanclas b_ageofbus b_bus_prime b_ownphone b_education_new_2-b_education_new_4 b_retailtype_new_2-b_retailtype_new_3, cluster(groupid)

scalar b5 = round(_b[tcarm], 0.001)
scalar se5 = round(_se[tcarm], 0.01)
scalar p5 = round(r(table)[4,2], 0.001)
scalar N5 = e(N)

reg log_e_profitregwk log_b_profitregwk tcarm stratum b_urbanclas b_ageofbus b_bus_prime b_ownphone b_education_new_2-b_education_new_4 b_retailtype_new_2-b_retailtype_new_3, cluster(groupid)

scalar b6 = round(_b[tcarm], 0.001)
scalar se6 = round(_se[tcarm], 0.01)
scalar p6 = round(r(table)[4,2], 0.001)
scalar N6 = e(N)


************************************************************
*************************INDIA******************************
************************************************************
//*SET DIRECTORY & LOAD DATA & GENERATE SCORES*//
clear
do "$FH/do/Scores/IND_HOC_Scores.do"

set more off

******************************************************************************************
//*RE-CLASSIFICATION OF BASELINE PARAMETERS*//

///CLASSIFICATION OF RETAIL TYPE INTO 3 NEW TYPES: "SHOP", "FOOD RETAIL" AND "NON-FOOD RETAIL"////

tab e_retailtype
tab e_retailtype, nol
gen e_retailtype_new = 1 if e_retailtype == 2
replace e_retailtype_new = 2 if e_retailtype == 1 | e_retailtype == 5 | e_retailtype == 9 | e_retailtype == 11
replace e_retailtype_new = 3 if e_retailtype_new != 1 & e_retailtype_new != 2
replace e_retailtype_new = . if e_retailtype < 0 | e_retailtype ==.
tab e_retailtype_new
label variable e_retailtype_new "Revised Retail Type Classification"
label define retailnew 1"Shop" 2"Food Retail" 3"Non-food Retail"
label values e_retailtype_new retailnew
tab e_retailtype_new
tab e_retailtype_new, nol
tab e_retailtype_new, gen(e_retailtype_new_)

*********************************************************************************
///RE-CLASSIFICATION OF EDUCATION INTO 4 LEVELS: "LESS THAN 5TH CLASS", "ABOVE 5TH CLASS", "COMPLETED HIGH SCHOOL" & "GRADUATE/POST-GRADUATE"///
tab e_education
tab e_education, nol
gen e_education_new = 1 if e_education <= 2
replace e_education_new = 2 if e_education == 3
replace e_education_new = 3 if e_education == 4
replace e_education_new = 4 if e_education >= 5
replace e_education_new = . if e_education < 0 | e_education ==.
tab e_education_new
label variable e_education_new "Revised Education Level"
label define educationnew 1"Less than 5th Grade" 2"Above 5th Grade" 3"Completed High School" 4"Graduate/Post-graduate"
label values e_education_new educationnew
tab e_education_new
tab e_education_new, nol
tab e_education_new, gen(e_education_new_)
*********************************************************************************
//RE-CLASSIFYING ORIENTATION 
tab orientation
tab orientation, nol
replace orientation = . if orientation == -1
replace orientation = 3 if tcarm == 0
tab orientation
tab orientation, nol
tab orientation, gen(orientation_new_)
tab orientation_new_1
tab orientation_new_2
tab orientation_new_3
tab orientation_new_4

*********************************************************************************
///RENAMING INDICATOR ON WHETHER A PERSON OWNS A PHONE///
rename e_qg1 e_ownphone
replace e_ownphone =. if e_ownphone < 0
tab e_ownphone

******************************************************************************************
//GENERATING LOG VALUES OF SALES IN BAD, GOOD & REGULAR WEEKS & REGULAR WEEK PROFITS//

pwcorr b_language e_age e_gender e_ageofbus e_bus_prime e_ownphone e_education_new e_retailtype_new

******************************************************************************************
//CONTROL MEANS OF OUTCOME VARIABLES//
summarize e_training_score if tcarm == 0
scalar ind_mean1 = round(r(mean), 0.001)
scalar ind_sd1 = round(r(sd), 0.001)

summarize e_training_score2 if tcarm == 0
scalar ind_mean2 = round(r(mean), 0.001)
scalar ind_sd2 = round(r(sd), 0.001)

summarize w1e_salesregwk if tcarm == 0
scalar ind_mean3 = round(r(mean), 0.001)
scalar ind_sd3 = round(r(sd), 0.001)

summarize log_e_salesregwk if tcarm == 0
scalar ind_mean4 = round(r(mean), 0.001)
scalar ind_sd4 = round(r(sd), 0.001)

summarize w1e_profitregwk if tcarm == 0
scalar ind_mean5 = round(r(mean), 0.001)
scalar ind_sd5 = round(r(sd), 0.001)

summarize log_e_profitregwk if tcarm == 0
scalar ind_mean6 = round(r(mean), 0.001)
scalar ind_sd6 = round(r(sd), 0.001)

//INTENT TO TREAT REGRESSIONS

reg e_training_score tcarm wave i._branch b_language e_gender e_ageofbus e_bus_prime e_ownphone e_education_new_2-e_education_new_4 e_retailtype_new_2-e_retailtype_new_3, r

scalar ind_b1 = round(_b[tcarm], 0.001)
scalar ind_se1 = round(_se[tcarm], 0.01)
scalar ind_p1 = round(r(table)[4,1], 0.001)
scalar ind_N1 = e(N)

reg e_training_score2 tcarm wave i._branch b_language e_gender e_ageofbus e_bus_prime e_ownphone e_education_new_2-e_education_new_4 e_retailtype_new_2-e_retailtype_new_3, r

scalar ind_b2 = round(_b[tcarm], 0.001)
scalar ind_se2 = round(_se[tcarm], 0.01)
scalar ind_p2 = round(r(table)[4,1], 0.001)
scalar ind_N2 = e(N)

reg w1e_salesregwk tcarm wave i._branch b_language e_gender e_ageofbus e_bus_prime e_ownphone e_education_new_2-e_education_new_4 e_retailtype_new_2-e_retailtype_new_3, r

scalar ind_b3 = round(_b[tcarm], 0.001)
scalar ind_se3 = round(_se[tcarm], 0.01)
scalar ind_p3 = round(r(table)[4,1], 0.001)
scalar ind_N3 = e(N)

reg log_e_salesregwk tcarm wave i._branch b_language e_gender e_ageofbus e_bus_prime e_ownphone e_education_new_2-e_education_new_4 e_retailtype_new_2-e_retailtype_new_3, r

scalar ind_b4 = round(_b[tcarm], 0.001)
scalar ind_se4 = round(_se[tcarm], 0.01)
scalar ind_p4 = round(r(table)[4,1], 0.001)
scalar ind_N4 = e(N)

reg w1e_profitregwk tcarm wave i._branch b_language e_gender e_ageofbus e_bus_prime e_ownphone e_education_new_2-e_education_new_4 e_retailtype_new_2-e_retailtype_new_3, r

scalar ind_b5 = round(_b[tcarm], 0.001)
scalar ind_se5 = round(_se[tcarm], 0.01)
scalar ind_p5 = round(r(table)[4,1], 0.001)
scalar ind_N5 = e(N)

reg log_e_profitregwk tcarm wave i._branch b_language e_gender e_ageofbus e_bus_prime e_ownphone e_education_new_2-e_education_new_4 e_retailtype_new_2-e_retailtype_new_3, r

scalar ind_b6 = round(_b[tcarm], 0.001)
scalar ind_se6 = round(_se[tcarm], 0.01)
scalar ind_p6 = round(r(table)[4,1], 0.001)
scalar ind_N6 = e(N)


file open table4 using "$FH/tables/Table 4.tex", write replace text
set more off
file write table4 "\documentclass[12pt]{article}" _n
file write table4 "\usepackage{amsmath}" _n
file write table4 "\usepackage{latexsym}" _n
file write table4 "\usepackage{amsfonts}" _n
file write table4 "\usepackage{xcolor}" _n
file write table4 "\usepackage{booktabs}" _n
file write table4 "\usepackage{tabularx}" _n
file write table4 "\usepackage{adjustbox}" _n
file write table4 "\begin{document}" _n

file write table4 "\begin{table}[htbp]" _n
file write table4 "\centering" _n
file write table4 "\begin{adjustbox}{width=1.1\textwidth}" _n
file write table4 "\begin{tabular}{p{17.165em}lllll}" _n
file write table4 "\multicolumn{6}{c}{\textbf{TABLE 4: INTENT TO TREAT ANALYSIS}} \\" _n
file write table4 "\midrule" _n
file write table4 "\midrule" _n

file write table4 "\multicolumn{1}{l}{} & \multicolumn{2}{c}{\textbf{Philippines}} &       & \multicolumn{2}{c}{\textbf{India}} \\" _n

file write table4 "\cmidrule{2-3}\cmidrule{5-6}    \multicolumn{1}{l}{\textit{\textbf{Dependent Variables}}} & \multicolumn{1}{c}{\textbf{Control Mean}} & \multicolumn{1}{c}{\textbf{Treatment Effect}} &       & \multicolumn{1}{c}{\textbf{Control Mean}} & \multicolumn{1}{c}{\textbf{Treatment Effect}} \\" _n

file write table4 "\cmidrule{2-3}\cmidrule{5-6}    \multicolumn{1}{l}{} & \multicolumn{1}{c}{\textbf{(1)}} & \multicolumn{1}{c}{\textbf{(2)}} &       & \multicolumn{1}{c}{\textbf{(3)}} & \multicolumn{1}{c}{\textbf{(4)}} \\" _n

file write table4 "\cmidrule{1-3}\cmidrule{5-6}    \multicolumn{1}{l}{\textbf{Business Practice Index (1-3)}} & \multicolumn{1}{c}{" (mean1) "} & \multicolumn{1}{c}{" (b1) "***} &       & \multicolumn{1}{c}{" (ind_mean1) "} & \multicolumn{1}{c}{" (ind_b1) "**} \\" _n

file write table4 "\multicolumn{1}{l}{} & \multicolumn{1}{c}{[" (sd1) "]} & \multicolumn{1}{c}{(" (se1) ")} &       & \multicolumn{1}{c}{[" (ind_sd1) "]} & \multicolumn{1}{c}{(" (ind_se1) ")} \\" _n
file write table4 "\multicolumn{1}{l}{} &       & \multicolumn{1}{c}{" (p1) "} &       &       & \multicolumn{1}{c}{" (ind_p1) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{N}} &       & \multicolumn{1}{c}{" (N1) "} &       &       & \multicolumn{1}{c}{" (ind_N1) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{Business Practice Index (0-1)}} & \multicolumn{1}{c}{" (mean2) "} & \multicolumn{1}{c}{" (b2) "**} &       & \multicolumn{1}{c}{" (ind_mean2) "} & \multicolumn{1}{c}{" (ind_b2) "*} \\" _n

file write table4 "\multicolumn{1}{l}{} & \multicolumn{1}{c}{[" (sd2) "]} & \multicolumn{1}{c}{(" (se2) ")} &       & \multicolumn{1}{c}{[" (ind_sd2) "]} & \multicolumn{1}{c}{(" (ind_se2) ")} \\" _n
file write table4 "\multicolumn{1}{l}{} &       & \multicolumn{1}{c}{" (p2) "} &       &       & \multicolumn{1}{c}{" (ind_p2) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{N}} &       & \multicolumn{1}{c}{" (N2) "} &       &       & \multicolumn{1}{c}{" (ind_N2) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{Regular Week Sales-Winsorized at 1\%}} & \multicolumn{1}{c}{" (mean3) "} & \multicolumn{1}{c}{" (b3) "} &       & \multicolumn{1}{c}{" (ind_mean3) "} & \multicolumn{1}{c}{" (ind_b3) "} \\" _n
file write table4 "\multicolumn{1}{l}{} & \multicolumn{1}{c}{[" (sd3) "]} & \multicolumn{1}{c}{(" (se3) ")} &       & \multicolumn{1}{c}{[" (ind_sd3) "]} & \multicolumn{1}{c}{(" (ind_se3) ")} \\" _n
file write table4 "\multicolumn{1}{l}{} &       & \multicolumn{1}{c}{" (p3) "} &       &       & \multicolumn{1}{c}{" (ind_p3) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{N}} &       & \multicolumn{1}{c}{" (N3) "} &       &       & \multicolumn{1}{c}{" (ind_N3) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{Regular Week Sales-Log Transformed}} & \multicolumn{1}{c}{" (mean4) "} & \multicolumn{1}{c}{" (b4) "} &       & \multicolumn{1}{c}{" (ind_mean4) "} & \multicolumn{1}{c}{" (ind_b4) "} \\" _n
file write table4 "\multicolumn{1}{l}{} & \multicolumn{1}{c}{[" (sd4) "]} & \multicolumn{1}{c}{(" (se4) ")} &       & \multicolumn{1}{c}{[" (ind_sd4) "]} & \multicolumn{1}{c}{(" (ind_se4) ")} \\" _n
file write table4 "\multicolumn{1}{l}{} &       & \multicolumn{1}{c}{" (p4) "} &       &       & \multicolumn{1}{c}{" (ind_p4) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{N}} &       & \multicolumn{1}{c}{" (N4) "} &       &       & \multicolumn{1}{c}{" (ind_N4) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{Regular Week Profits-Winsorized at 1\%}} & \multicolumn{1}{c}{" (mean5) "} & \multicolumn{1}{c}{" (b5) "} &       & \multicolumn{1}{c}{" (ind_mean5) "} & \multicolumn{1}{c}{" (ind_b5) "} \\" _n
file write table4 "\multicolumn{1}{l}{} & \multicolumn{1}{c}{[" (sd5) "]} & \multicolumn{1}{c}{(" (se5) ")} &       & \multicolumn{1}{c}{[" (ind_sd5) "]} & \multicolumn{1}{c}{(" (ind_se5) ")} \\" _n
file write table4 "\multicolumn{1}{l}{} &       & \multicolumn{1}{c}{" (p5) "} &       &       & \multicolumn{1}{c}{" (ind_p5) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{N}} &       & \multicolumn{1}{c}{" (N5) "} &       &       & \multicolumn{1}{c}{" (ind_N5) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{Regular Week Profits-Log Transformed}} & \multicolumn{1}{c}{" (mean6) "} & \multicolumn{1}{c}{" (b6) "} &       & \multicolumn{1}{c}{" (ind_mean6) "} & \multicolumn{1}{c}{" (ind_b6) "} \\" _n
file write table4 "\multicolumn{1}{l}{} & \multicolumn{1}{c}{[" (sd6) "]} & \multicolumn{1}{c}{(" (se6) ")} &       & \multicolumn{1}{c}{[" (ind_sd6) "]} & \multicolumn{1}{c}{(" (ind_se6) ")} \\" _n
file write table4 "\multicolumn{1}{l}{} &       & \multicolumn{1}{c}{" (p6) "} &       &       & \multicolumn{1}{c}{" (ind_p6) "} \\" _n
file write table4 "\multicolumn{1}{l}{\textbf{N}} &       & \multicolumn{1}{c}{" (N6) "} &       &       & \multicolumn{1}{c}{" (ind_N6) "} \\" _n
file write table4 "\midrule" _n
file write table4 "\midrule" _n
file write table4 "\multicolumn{6}{p{58em}}{Notes: This table presents the impact of training on business practices and performance for the experiments conducted in India and the Philippines. Control means are presented in columns 1 and 3 and standard deviations in square brackets. Each coefficient reported in columns 2 and 4 is from the regression for each outcome variable on the treatment variable. Covariates include time of survey (India), gender, age of business, own a cellphone indicator, primary source of income indicator, education level, business type, and variables used for stratification and language. Heteroskedasticity-robust standard errors in parentheses. * Denotes significance at 10\%-level, ** at the 5\%-level, and *** at the 1\%-level.} \\" _n
file write table4 "\bottomrule" _n
file write table4 "\end{tabular}%" _n
file write table4 "\label{tab:addlabel}%" _n
file write table4 "\end{adjustbox}" _n
file write table4 "\end{table}%" _n


file write table4 "\end{document}" _n


file close table4
set more on
